<template>
    <div class='commonEdit'  v-loading="loading" v-if="shows">
        <el-tabs type="border-card" v-if='tabJson.length>1' v-model="tabs">
          
            <el-tab-pane v-for="(item,index) in tabJson" :key="index" :name="item.tabName" :label="item.tabName" :style="item.tabStyle">
                <div class='boxs'>
                    <div v-for="(card,index2) in item.list" :key="index2" :style="card.width" class='cards '>
                        <el-card shadow="always" :style="card.height">
                            <div slot="header" class="clearfix">
                                <span><i class='el-icon-warning' style='margin-right:5px;margin-left:10px'></i>{{card.title}}</span>
                                <el-button style="float: right; padding: 3px 0" type="text"></el-button>
                            </div>
                            <div style='height:100%;'>
                                <my-form ref="myForms" :list="card.list" :w="card.w" :data="data" :rules='card.rules' v-if="card.type=='form'&&showForm" @input="changeInput" @funeralItemSelectEvent="funeralItemSelectEvent" :appid="appid"></my-form>
                                <table-edit-button ref="tableEdits"   @remove="remove"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='tableEditButton'&&showForm" @input="changeInput" :appid="appid"></table-edit-button>
                               
                                <table-edit ref="tableEdits"  @remove="remove" :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table'&&showForm" @input="changeInput"  :appid="appid"></table-edit>
                                <table-form ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table_form'&&showForm" @input="changeInput"  :appid="appid"></table-form>
                                <table-edit2 ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table2'&&showForm" @input="changeInput" :appid="appid"></table-edit2>
                                <table-edit3 ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table3'&&showForm" @input="changeInput" :appid="appid"></table-edit3>
                                
                                <funeral-item-table ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='funeral_item_table'&&showForm" @input="changeInput" :params="params" :appid="appid"></funeral-item-table>
                                <order-food   :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='order_food'&&showForm" @input="changeInput" :params="params" :appid="appid"></order-food>
                                <commonList ref="commonList" @goSearch="goSearch"  @openWin="openWin" sKey="" :exId="sId" :sKey2="card.dataField"  searchs="" listnames='' v-if="card.type=='list'" :appid="appid"></commonList>
                            </div>
                        </el-card> 
                    </div>
                </div>
            </el-tab-pane> 
        </el-tabs>
        <div v-else class='el-tabs' style='overflow:auto'>
            <div class='el-tabs__content'>
                <div class='boxs' v-for="(tab,indexss) in tabJson" :key="indexss">
                    <div v-for="(card,index2) in tab.list" :key="index2" :style="card.width" class='cards ' >
                        <el-card shadow="always" :style="card.height">
                            <div slot="header" class="clearfix">
                                <span><i class='el-icon-warning' style='margin-right:5px;'></i>{{card.title}}</span>
                                <el-button style="float: right; padding: 3px 0" type="text"></el-button>
                            </div>
                            <div  style=''>
                                <my-form ref="myForms" :list="card.list" :data="data" :rules='card.rules' v-if="card.type=='form'&&showForm" @input="changeInput" @funeralItemSelectEvent="funeralItemSelectEvent" :appid="appid"></my-form>
                                <table-edit-button ref="tableEdits"   @remove="remove"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='tableEditButton'&&showForm" @input="changeInput" :appid="appid"></table-edit-button>
                                
                                <table-edit ref="tableEdits"   @remove="remove"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table'&&showForm" @input="changeInput" :appid="appid"></table-edit>
                                <table-edit2 ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table2'&&showForm" @input="changeInput" :appid="appid"></table-edit2>
                                <table-edit3 ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table3'&&showForm" @input="changeInput" :appid="appid"></table-edit3>
                                <table-form ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='table_form'&&showForm" @input="changeInput" :appid="appid"></table-form>
                                <funeral-item-table ref="tableEdits"  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='funeral_item_table'&&showForm" @input="changeInput" :params="params" :appid="appid"></funeral-item-table>
                                <order-food  :listField="card.list" :dataField="card.dataField" :data="data" v-if="card.type=='order_food'&&showForm" @input="changeInput" :params="params" :appid="appid"></order-food>
                                
                            </div>
                        </el-card> 
                    </div>
                </div>
            </div>
            
        </div>
        
        <div class='btns'>
           <div class='btns_wrap'>
               <div class='button_item' v-for="(item,index) in buttonJson" :key="index">
                   <el-form ref="form"  label-width="70px" v-if="item.type=='sn'"  @keyup.enter.native="loadDatas2" class='sn' style='margin-top:5px' @submit.native.prevent>
                        <el-form-item :label="item.name">
                            <el-input v-model="sn" autofocus style='width:160px;height:30px' ></el-input>
                        </el-form-item>
                   </el-form>
                   <el-button :type="item.buttonType" :icon="item.icon" size="small"  @click="btnClick(item)" v-else-if="item.menu.length==0" style='margin-top:10px'>{{item.name}}</el-button>
                   
                   <el-dropdown v-else @command="btnClick">
                        <el-button :type="item.buttonType" size="small"  style='margin-top:10px'>
                        {{item.name}}<i class="el-icon-arrow-down el-icon--right"></i>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item icon="el-icon-printer" :command="itemc"  v-for="(itemc,index2) in item.menu"   :key="index2">{{itemc.name.split("#")[0]}}</el-dropdown-item>
                        
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
               
             
           </div>
           
        </div>
         <el-dialog
            width="90%"
            title="打印预览"
            :visible.sync="innerVisible"
            append-to-body>
             <common-print :printDatas="printData" style='height:85VH' v-if="isPrint=='N'"></common-print>
       

        </el-dialog>
            
        <common-print :printDatas="printData" style='height:10px;position:absolute;bottom:-10px;'  v-if="isPrint=='Y'"></common-print>
        <iframe :src="src" style='height:1px;position:absolute;bottom:-10px;'></iframe>

       
    </div>
</template>
<script>
import Vue  from 'vue'
import CommonList  from '../components/list/commonList.vue'
import MyForm  from '../components/edit/Form.vue'
import tableEdit  from '../components/edit/tableEdit.vue'
import tableEditButton  from '../components/edit/tableEditButton.vue'
import tableEdit2  from '../components/edit/tableEdit2.vue'
import tableEdit3  from '../components/edit/tableEdit3.vue'
import TableForm  from '../components/edit/TableForm.vue'
import FuneralItemTable  from '../components/byg/FuneralItemTable.vue'
import OrderFood  from '../components/byg/OrderFood.vue'
import CommonPrint  from './common/print/CommonPrint.vue'

export default {
    name:"commonEditBase",
    props:["commonEditData"],
    components: {
       MyForm,
       tableEdit,
       tableEditButton,
       tableEdit2,
       tableEdit3,
       FuneralItemTable,
       OrderFood,
       TableForm,
       CommonList,
       CommonPrint
    },
    data(){
        return{
           shows:false,
           innerVisible:false,
           print_src:"",
           printData:{},
           printData2:{},
           tabJson:[],
           buttonJson:[],
           buttonJson2:[],
           sKey:'',
           fieldPath:'',
           filename:'',
           isPrint:"N",
           url:'',
           sId:'',
           cId:'',
           sn:'',
           data:{},
           saveList:"",
           oldData:{},
           showForm:false,
           loading:true,
           button:{},
           company:'',
           params:'',
           paramKey:'',
           exData:{},
           src:'',
           tabs:'',
           appid:'',
           param_key:"",//额外的参数变量
           href:''//当前页面完整的url,用于保存刷新的时候，返回给父界面
        }
    },
    beforeRouteLeave(to, from, next){
        console.log("to, from, next=="+to+"="+from+"="+next)
        console.log(to);
        console.log(from)
        if(from.query.filename2=="殡仪馆系统/殡仪服务"){
            
            try{
                if(this.GLOBAL.dialogsImg)
                    this.GLOBAL.dialogsImg.get_actionType("closeSignal");
                this.GLOBAL.dialogsImg=null;
                this.GLOBAL.dialogs=null;
                this.GLOBAL.readId="";
                if(this.GLOBAL.socketsImg)
                    this.GLOBAL.socketsImg.close();
                if(this.GLOBAL.sockets)
                this.GLOBAL.sockets.close();
                
                this.GLOBAL.socketsImg=null;
                this.GLOBAL.sockets=null;
            }catch(e){}
        }
    },
    created(){
        this.sKey=this.$route.query.sKey;
        this.fieldPath=this.$route.query.fieldPath;
        this.filename=this.$route.query.filename2;
        this.sId=this.$route.query.sId;
        if(this.$route.query.cId){
            this.cId=this.$route.query.cId;
        }
        let isCopy=this.$route.query.isCopy;

        if(this.$route.query.param_key){
            this.param_key=this.$route.query.param_key;
        }
        if(isCopy=='Y'){
            this.cId=this.sId;
            this.sId="";
        }
        this.company=this.$route.query.company;
        if(this.$route.query.appid){
            this.appid=this.$route.query.appid;
        }
         
        if(this.$route.query.params){
            this.params=this.$route.query.params;//目前用于殡仪服务项目区分是哪个部门选择的，从cs_winUrl直接传参
        }
         if(this.$route.query.paramKey){
            this.paramKey=this.$route.query.paramKey;
        }
        this.href = window.location.href; /* 获取完整URL */
        if(this.commonEditData){
            if(this.commonEditData.fieldPath){
                this.fieldPath=this.commonEditData.fieldPath;
            }
        
            if(this.commonEditData.filename2){
                this.filename=this.commonEditData.filename2;
            }
            if(this.commonEditData.sId){
                this.sId=this.commonEditData.sId;
            }
            if(this.commonEditData.appid){
                this.appid=this.commonEditData.appid;
            }
            if(this.commonEditData.param_key){
                this.paramKey=this.commonEditData.param_key;
            }
            if(this.commonEditData.exData){
                this.exData=this.commonEditData.exData;
            }
        }
        console.log("loadData========================================================")
            this.loadData();
    },
    mounted(){
       
        window.setTimeout(function(){
            let els=document.getElementsByClassName("el-card__header");
            for(let i=0;i<els.length;i++){
                els[i].style.borderTop="2px solid #66b1ff"
            }
            
        },1000)
        
    },
    watch:{
        
       /* commonEditData:{
            handler: function (newVal) {
                console.log("11111111111111111111111111111")
                if(this.commonEditData){
                    if(this.commonEditData.fieldPath){
                        this.fieldPath=this.commonEditData.fieldPath;
                    }
                
                    if(this.commonEditData.filename2){
                        this.filename=this.commonEditData.filename2;
                    }
                    if(this.commonEditData.sId){
                        this.sId=this.commonEditData.sId;
                    }
                    if(this.commonEditData.appid){
                        this.appid=this.commonEditData.appid;
                    }
                    if(this.commonEditData.param_key){
                        this.param_key=this.commonEditData.param_key;
                    }
                }
                console.log("ddddddddddddddddddddddddddddddddddddddddd");
                // console.log("data===================================================")
                this.loadData()
            },      
            deep: true    //深度监听
        }*/
    },
    updated(){
    },
    methods:{
        remove(data){
            let datas=JSON.parse(data);
            let pre=datas.pre;
            let exdata=datas.exdata;
            this.data[pre].splice(exdata,1);
        },
        loadData(){
            this.shows=false;
            let sef=this;
            let data={};
            data.sKey2=this.sKey;
            data.fieldPath=escape(this.fieldPath);
            data.filename=escape(this.filename);
               
            console.log("commonEditView==appid="+this.appid);
            this.$post(this.appid,'api/view/commonEditView',data).then(data=>{
                console.log(data);
                
                sef.tabJson=JSON.parse(JSON.stringify(data.tabFields));
               
                this.tabs=sef.tabJson[0].tabName;
                sef.buttonJson=data.buttonFields;
                sef.buttonJson2=data.buttonFields;
                sef.url=data.url;
               
                 for(let i=0;i<this.tabJson.length;i++){
                    if(this.tabJson[i].list.length==1){
                        this.tabJson[i].list[0].width=this.tabJson[i].list[0].width+";height:100%;";
                        
                        this.tabJson[i].list[0].height="height:98%;display:flex;flex-direction:column;";
                    }
                    
                }
                sef.shows=true;
                try{
                    sef.loadDatas(false);
               
                }catch(e){}
                 window.setTimeout(function(){
                     try{
                        let el=document.getElementsByClassName("el-tabs__content");
                        for(let i=0;i<el.length;i++){
                            el[i].style.flex="1";
                            el[i].style.overflow="auto";
                            el[i].style.paddingBottom="10px";
                        }
                        let el2=document.getElementsByClassName("sn");
                        el2[0].parentNode.style.position="absolute";
                        el2[0].parentNode.style.bottom="-10";
                        el2[0].parentNode.style.left="0";
                     }catch(e){}
                   

                },1000)
                
            });
        },
        loadDatas2(){
            this.sId="";
            this.loadDatas(true);
            this.sn="";
        },
        loadDatas(isSet){
            let sef=this;
            let data_={};
            data_.sId=sef.sId;
            data_.cId=sef.cId;
            data_.company=sef.company;
            data_.sSn=sef.sn;
            if(this.paramKey){
                if(this.commonEditData){
                    let paramKeys=this.paramKey.split(",");
                    let params=this.commonEditData.params;
                    for(let i=0;i<paramKeys.length;i++){
                        let key=paramKeys[i];
                        data_[key]=params[key];
                    }
                    
                }else{
                
                    let paramKeys=this.paramKey.split(",");
                    for(let i=0;i<paramKeys.length;i++){
                        let key=paramKeys[i];
                        data_[key]=this.$route.query[key];
                    }
                    
                }
            }
            
            data_["filename2"]=this.filename;

            //按钮额外的参数，在cs_winButton表中wb_key和wb_params两个字段决定
            if(this.param_key){
                let params=this.param_key.split(",");
                for(let i=0;i<params.length;i++){
                    let val=this.$route.query[params[i]];
                    data_[params[i]]=escape(val);
                }
            }
            data_["exData"]=JSON.stringify(this.exData);
            console.log("loadData==appid="+this.appid);
            console.log("url===="+sef.url);
            sef.$post(this.appid,sef.url,data_).then(data=>{
                try{
                  
                    console.log("data===================================");
                    console.log(data);
                    sef.data=data[0].data;
                    sef.saveList=data[0].saveList;
                    sef.oldData=JSON.parse(JSON.stringify(data[0].data));
                    if(isSet){
                        let forms=this.$refs.myForms;
                        for(let i=0;i<forms.length;i++){
                            let message=forms[i].setData(sef.data);
                           
                        }
                    }
                    if(data[0].field){
                        let fields= data[0].field;
                        for(let i=0;i<this.tabJson.length;i++){
                            for(let j=0;j<this.tabJson[i].list.length;j++){
                                for(let h=0;h<this.tabJson[i].list[j].list.length;h++){
                                    let id=this.tabJson[i].list[j].list[h].id;
                                    if(fields[id]=='N'){
                                        this.tabJson[i].list[j].list[h].isReadOnly='Y'
                                    }
                                }
                            }
                        }
                    }
                    if(data[0].dataSelectField){
                        let fields= data[0].dataSelectField;
                        for(let i=0;i<this.tabJson.length;i++){
                            for(let j=0;j<this.tabJson[i].list.lengtgh;j++){
                                for(let h=0;h<this.tabJson[i].list[j].list.length;h++){
                                    let id=this.tabJson[i].list[j].list[h].id;
                                    if(fields[id]){
                                        this.tabJson[i].list[j].list[h].dataSource=fields[id]
                                    }
                                }
                            }
                        }
                    }
                    if(data[0].button||data[0].data.button){
                        if(data[0].button)
                            sef.button=data[0].button;
                        else
                            sef.button=data[0].data.button
                        let buttons=[];
                        for(let i=0;i<sef.buttonJson2.length;i++){
                            let id=sef.buttonJson2[i].id;
                            if(sef.button[id]){
                                if(sef.button[id]!='N'){
                                    buttons.push(sef.buttonJson2[i])
                                }
                            }else{
                                
                                buttons.push(sef.buttonJson2[i])
                            }
                        }
                        sef.buttonJson=buttons;
                    }
                    
                    sef.showForm=true;
                    sef.loading=false;
                }catch(e){

                }

                window.setTimeout(function(){
                     let isBr="N";
                    let height="";
                    let els2=document.getElementsByClassName("cards");
                    for(let i=0;i<els2.length;i++){
                        let width=Number(els2[i].style.width.replace("%",""));
                        if(width<90&&isBr=='N'){
                            isBr="Y";
                            height=els2[i].clientHeight;
                        }else if(width<90&&isBr=='Y'){
                            let height_=els2[i].clientHeight;
                            if(height>height_){
                                els2[i].style.height=height+'px';
                                els2[i].children[0].style.height=(height-8)+'px'
                          
                            }else{
                                els2[i-1].style.height=height_+'px';
                                els2[i-1].children[0].style.height=(height_-8)+'px'
                            }
                            isBr='N'
                            
                        }
                    }
                },1000)
                
            })
        },
        changeInput(data){
            let datas=JSON.parse(data);
            let id=datas.id;
            let pre=datas.pre;
            let val=datas.val;
            let exdata=datas.exdata;
            //console.log("pre==============="+pre+"=="+id+"="+val);
           // console.log(this.data)
            try{
                 //用于表格多条数据，不确定有多少条数据
                if(exdata||exdata=='0'){
                /* let num=Number(exdata);
                    let data_={};
                    
                    if(this.data[pre].length<num){
                        data_[id]=val;
                        this.data[pre].push(data_);
                    }else*/
                    this.data[pre][exdata]=JSON.parse(val);
                }else if(datas.index!=undefined&&datas.index!=""){//增对多条数据，但能知道有多少条
                   
                    let index=datas.index;//用于行号
                    this.data[pre][index][id]=val;
                }else{//普通input
                    this.data[pre][id]=val;
                }
            }catch(e){

            }
           
            
        },
        funeralItemSelectEvent(data){
            console.log("addFuneralEvent===============================")
            if(this.$refs.tableEdits)
                this.$refs.tableEdits[this.$refs.tableEdits.length-1].addItem(data);
        },
        getScrollTop(){
           return  this.$refs.tableEdits[0].getScrollTop();
        },
        btnClick(item){
          
            let url=item.url;
            let type=item.type;
            let msg=item.msg;
            if(type=="save"){
                if(!msg)
                    this.save(item);
                
                else{
                    this.$confirm(msg, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                        }).then(() => {
                             this.save(item);
                        }).catch(() => {
                                
                     });
                }
            }else if(type=="close"){
                let item_={};
                item_.type="close";
                if(this.commonEditData){
                    item_.closeType="dialog";
                }
                this.$emit("closeWin",JSON.stringify(item_));
                //parent.postMessage(JSON.stringify(item_),'*');
            }else if(type=="printViewMenu"){
                let key=item.printKey.split(".");
                let vals="";
                if(key.length>1){
                    vals=this.data[key[0]][key[1]];
                }else
                    vals=this.data[key[0]]

                
                if(item.url){
                    let items={};
                    items.buttonName="打印"+item.url;
                    items.text="打印"+item.url;
                    items.url="/commonPrint?printName="+item.url+"&sCurItem="+vals+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid;
                    this.$emit("openWin",JSON.stringify(items))
                    
                   
                    //parent.postMessage(JSON.stringify(items),'*');
                }else{
                    let names=item.name.split("#");
                    let isPrint=names.length>1 ? names[1]:"";
                    let items={};
                    items.buttonName="打印"+names[0];
                    items.text="打印"+names[0];
                    items.url="/commonPrint?printName="+names[0]+"&sCurItem="+vals+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid+"&isPrint="+isPrint;
                   // parent.postMessage(JSON.stringify(items),'*');
                    let printData_={};
                    printData_.printName=names[0];
                    printData_.sCurItem=vals;
                    printData_.appid=this.appid;
                    printData_.token=sessionStorage.getItem("token");
                    printData_.isPrint=isPrint;
                    if(isPrint=="Y"){
                        this.isPrint="Y";
                    }else{
                        this.isPrint="N";
                        this.innerVisible=true;
                         //this.$emit("openWin",JSON.stringify(items))
                    }
                    
                    this.printData=printData_;
                    
                       
                }
               
            }else if(type=="printMenu"){
                let key=item.printKey.split(".");
                let vals="";
                if(key.length>1){
                    vals=this.data[key[0]][key[1]];
                }else
                    vals=this.data[key[0]]
                
                if(item.url){
                    this.src=''
                    var timestamp = (new Date()).getTime()/1000;
                    this.src="/commonPrint?printName="+item.url+"&sCurItem="+vals+"&isPrint=Y&timestamp="+timestamp+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid;
                }else{
                    this.src=''
                    var timestamp = (new Date()).getTime()/1000;
                    this.src="/commonPrint?printName="+item.name+"&sCurItem="+vals+"&isPrint=Y&timestamp="+timestamp+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid;
                }
                
                
            }else if(type=="openWin"){
                if(this.sId==""){
                     this.$message.error('请先保存数据');
                     return;
                }
                let items={};
                items.buttonName=item.name;
                items.text=item.name;
                let url=item.url;
                url=url.replace("#ids#",this.sId);
                url=url+"&appid="+this.appid;
                items.url=url;
                var searchParams = this.queryURLparams(url);
                items.appid=this.appid;
                items.model=searchParams.model;
                items.filename2=searchParams.filename2;
                items.key=searchParams.key;;
                items.sId=searchParams.sId;
                items.fieldPath=searchParams.fieldPath;
                this.$emit("openWin",JSON.stringify(items))

            }
        },
        queryURLparams(url) {
            let obj = {}
            if (url.indexOf('?') < 0) return obj
            let arr = url.split('?')
            url = arr[1]
            let array = url.split('&')
            for (let i = 0; i < array.length; i++) {
                let arr2 = array[i]
                let arr3 = arr2.split('=')
                obj[arr3[0]] = arr3[1]
            }
            return obj

        },
        checkData(newObj,oldObj){
            let data={};
            for(let key in newObj){
                let d=newObj[key];
                let isOk=true;
                if(oldObj){
                    let d_=oldObj[key];
                    if(d==d_)
                        isOk=false;
                }
                 if((","+this.saveList+",").indexOf(","+key+",")!=-1){//必保存字段
                    isOk=true;
                    
                }
                if(isOk){
                    data[key]=d;
                }
               
            }
            let isEmpty=true;
            for(let key in data){
                isEmpty=false;
            }
            if(!isEmpty){
                data[newObj.key_field]=newObj[newObj.key_field];
            }
            return data;
        },
        checkDataOld(newObj,oldObj){
            let data={};
            for(let key in newObj){
                let d=newObj[key];
                let isOk=true;
                let d_="";
                if(oldObj){
                    d_=oldObj[key];
                    if(d==d_)
                        isOk=false;
                }
               
                
                if((","+this.saveList+",").indexOf(","+key+",")!=-1){//必保存字段
                    isOk=true;
                   
                }
                if(isOk){
                    data[key]=d_;
                }
            }
            let isEmpty=true;
            for(let key in data){
                isEmpty=false;
            }
            if(!isEmpty){
                data[newObj.key_field]=newObj[newObj.key_field];
            }
            return data;
        },
        save(item){
            this.loading=true;
            let forms=this.$refs.myForms;
            let isOk=true;
            for(let i=0;i<forms.length;i++){
                let message=forms[i].validate();
                if(message){
                    this.$message.error(message);
                    isOk=false;
                    this.loading=false;
                    break;
                }
               
            }
            if(isOk){

                let data_={};
                let dataold_={};
                let  isCover="N";
                if(this.sId){
                    isCover="Y";
                    for(let key in this.data){
                        let d=this.data[key];
                        let d_=this.oldData[key];
                        if(Array.isArray(d)){
                            let datas=[];
                            let datasold=[];
                            for(let i=0;i<d.length;i++){
                                let da=d[i];
                                let da_=null;
                                let id=da.key_field;
                               // console.log("id======================="+id);
                               // console.log(da);
                                for(let j=0;j<d_.length;j++){
                                    let da__=d_[j];
                                    
                                    if(id==da__["key_field"])
                                        da_=da__;
                                }
                                console.log(da);
                                console.log(da_);
                                let data__=this.checkData(da,da_);
                                let dataold__=this.checkDataOld(da,da_);
                                let isEmpty=true;
                                for(let key_ in data__){
                                    isEmpty=false;
                                }
                                if(!isEmpty){
                                    datas.push(data__);
                                    datasold.push(dataold__);
                                }
                            }
                            if(datas.length>0){
                                data_[key]=datas;
                                dataold_[key]=datasold;
                            }
                        }else{
                            let data__=this.checkData(d,d_);
                            let dataold__=this.checkDataOld(d,d_);
                            let isEmpty=true;
                            for(let key_ in data__){
                                isEmpty=false;
                            }
                            if(!isEmpty){
                                data_[key]=data__;
                                dataold_[key]=dataold__;
                            }
                        }
                    }
                }else{
                    data_=this.data;
                }
                let urls=item.url;
                let appid_=this.appid;
                if(item.url.indexOf("appid")!=-1){
                    let urls_=urls.split("#");
                    urls=urls_[1];
                    appid_=urls_[0].replace("appid=","");
                }
                this.$post(appid_,urls,{data:JSON.stringify(this.data),dataNew:JSON.stringify(data_),isCover:isCover,dataOld:JSON.stringify(dataold_),filename2:escape(this.filename)}).then(data=>{
                    
                    this.$alert(unescape(data[0].msg), '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            if(data[0].status=='+OK'){
                                 if(this.tabJson[0].isClose=="Y"){
                                    let data_={};
                                    data_.type="close";
                                    if(this.commonEditData){
                                        data_.closeType="dialog";
                                    }
                                    this.$emit("closeWin",JSON.stringify(data_))
                                    //parent.postMessage(JSON.stringify(data_),'*');
                                }
                            }
                        }
                    });
                    if(data[0].status=="+OK"){
                        this.sId=data[0].sId;
                        this.loadDatas(true);
                        let data_={};
                        data_.type="goSearch";
                        data_.url=this.href;
                        if(this.commonEditData){
                            data_.searchType="dialog";
                        }
                        //parent.postMessage(JSON.stringify(data_),'*');
                        this.$emit("goSearch",JSON.stringify(data_))
                       
                    }
                    this.loading=false;
                    
                }).catch(err=>{
                    console.log("err==============")
                    console.log(err);
                    this.loading=false;
                    this.$alert("报错出错:"+err.message, '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            
                        }
                    });
                });
            }
            
        },
        goSearch(data){
            console.log("goSearch---------------------------------------------"+data)
            this.sId=data;
            this.loadDatas(true);
            this.tabs=this.tabJson[0].tabName;
        },
        openWin(data){
            this.$emit("openWin",data)
        }
    }
}
</script>
<style scoped>
    .commonEdit{
       display:flex;
       box-sizing: border-box;
       -moz-box-sizing: border-box;
       -webkit-box-sizing: border-box;
       flex:1;
       border-radius: 5px;
       flex-direction: column;
       position: relative;
       overflow:hidden;
       height:100%;
    }
    .el-tabs{
        width:100%;
        flex:1;
        overflow:hidden;
        /*margin:10px;*/
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        display: flex;
        flex-direction: column;
    }
    .el-tabs__content{
        height:100%;
        overflow: auto;
        padding-bottom:10px !important;
    }
    .boxs{
        
        display:flex;
        flex-direction: row;
        display: -webkit-flex;
        justify-content: center;
        flex-direction: row;
        flex-wrap: wrap;
        align-items:flex-start;
        height:100%;
    }
    .cards{
        display:inline-block;
        /*float:left;*/
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        margin-bottom:5px;
        margin-left:2px;
    }
    .el-card__body{
         box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        padding-bottom: 30px;;
    }
    .btns{
        width:100%;
        height:50px;
        border-top:1px solid #ddd;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;

    }
    .btns_wrap{
        border-top:1px solid #ddd;
        height:100%;
        width:100%;
        background:#f6f3f3;
        text-align: center;
        padding-top:0px;
        border-top:1px solid #ddd;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
    }
    input{
        height:25px;
    }
    .el-input__inner{
        height:25px;
    }
    .el-card__header{
        padding:10px 18px;
        border-bottom:1px solid blue;
    }
    .el-card{
        margin-top:5px;
        color:#66b1ff;
    }

    

  /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  ::-webkit-scrollbar{
    width: 12px;
    height: 12px;
    background-color: #F5F5F5;
  }

  /*定义滚动条轨道 内阴影+圆角*/
  ::-webkit-scrollbar-track {
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    background-color: #F5F5F5;
  }

  /*定义滑块 内阴影+圆角*/
  ::-webkit-scrollbar-thumb{
    border-radius: 10px;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);
    background-color: #c8c8c8;
  }

  .el-input__inner{
      font-family: 微软雅黑;
  }
  .button_item{
      display:inline-block;
      margin-left:6px;
  }
  
</style>
<style >
    .el-card__body{
        flex:1;
        overflow-y:auto;
        overflow-x:hidden;
        padding-bottom:30px ;
    }
    .el-tabs__header{
      height:39px;
  }
  .el-card{
      display:flex;
      flex-direction: column;
  }
  .el-tabs__content{
      padding:0 !important;
  }
</style>